#Andrew Gooch
#April 11, 2017
#Ripping Yarn, Political Communications
#Replication R file 8: Sample sizes for in-text and appendix references

#This R file is simply used to output sample sizes by party ID due to random assignment into control or treatment

#required packages
library(arm)
library(ggplot2)
library(grid)
library(gridExtra)
library(foreign)
library(survey)



######################
### MARCH
######################

#loads data. Please change to your file directory where the data is located in your terminal
Mar15 <- read.dta("C:/Users/agooch/Dropbox/Dissertation/Data/Experiments/Aggregated Dataset/315.dta")
attach(Mar15)

table(Gtreatment,Gmonthyear)


# overall treatment n sizes, nonresponse = 6
table(Mar15$Gcontrol)
table(Mar15$Ggoodjust)

#overall favorability, nonresponse = 6
table(Mar15$Gfavor)

#####################
# by PID, independent leaners are coded as partisans

#pid for newer question wording
table(Mar15$Gpid3)
Mar15$pid5_new <- Mar15$Gpid3
Mar15$pid5_new[Mar15$Gpid3 == 1] <- -1 #dem
Mar15$pid5_new[Mar15$Gpid3 == 2] <-  1#rep
Mar15$pid5_new[Mar15$Gpid3 == 3] <- 0 #ind
Mar15$pid5_new[Mar15$Gpid3 == 4] <- 0 #other
table(Mar15$pid5_new)


table(Mar15$Gindlean)
Mar15$leaner_new <- Mar15$Gindlean
Mar15$leaner_new[Mar15$Gindlean == 1] <- -1 #lean dem
Mar15$leaner_new[Mar15$Gindlean == 2] <-  1#lean rep
Mar15$leaner_new[Mar15$Gindlean == 3] <- 0 #neither
table(Mar15$leaner_new)


#3-point with leaners as partisans
Mar15$PID3_lean_new <- Mar15$leaner_new
Mar15$PID3_lean_new[Mar15$leaner_new== -1 | Mar15$pid5_new == -1] <- 1 #dem
Mar15$PID3_lean_new[Mar15$leaner_new== 0] <- 0 #ind
Mar15$PID3_lean_new[Mar15$leaner_new== 1 | Mar15$pid5_new == 1] <- -1 #rep
table(Mar15$PID3_lean_new)
table(Mar15$PID3_lean_new, Mar15$pid5_new)
table(Mar15$PID3_lean_new, Mar15$leaner_new)


# pid treatment and favorability n sizes, nonresponse = 6

#Democrats
table(Mar15$Gcontrol[Mar15$PID3_lean_new==1])
82+71+28+12+6+41 

table(Mar15$Ggoodjust[Mar15$PID3_lean_new==1])
94+68+23+10+5+35

table(Mar15$Gfavor[Mar15$PID3_lean_new==1])
89+153+121+48+15+49

#Republicans
table(Mar15$Gcontrol[Mar15$PID3_lean_new==-1])
25+49+37+26+20+38  

table(Mar15$Ggoodjust[Mar15$PID3_lean_new==-1])
32+51+24+21+21+39  

table(Mar15$Gfavor[Mar15$PID3_lean_new==-1])
13+34+69+79+160+28 

#Independents
table(Mar15$Gcontrol[Mar15$PID3_lean_new==0])
24+13+18+3+2+13

table(Mar15$Ggoodjust[Mar15$PID3_lean_new==0])
23+14+10+2+2+24  

table(Mar15$Gfavor[Mar15$PID3_lean_new==0])
4+16+52+20+26+30 







